<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
    <%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页轮播排序</title>
    <link  href="../images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="../css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/messages_doctor_mes.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/sweetalert.css?cache=<%=Math.random()%>" >
    <script src="../js/jquery-1.9.1.min.js"></script>

</head>
<body>
    <%@ include file="../header.jsp"%>
    <!--内容-->
    <div class="containerone">
    <%@ include file="../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont" id='turn_box'>
<!--右边导航下面内容-->
          <div class="message_hos_news_container">
                <div class="department_detail ui_padding_top" id="doctor_detail">
                <table class="department_detail_table">
                <tr class='department_detail_tittle'>
                <th class='ui_width_s'>序号</th>
                <th class='ui_widthone'>图片</th>
                <th class='ui_widther'>新闻名称</th>
                <th class='ui_widthone'>作者</th>
                <th class='ui_widthone'>操作</th>
                </tr>
              <template  v-for="turn in turns ">
                <tr class="department_detail_home_news">
                <td v-html="turn.order_id"></td>
                <td class="hospital_news_order" align="center" valign="middle">
                    <img v-bind:src="turn.img[0].src">
                </td>
                <td v-html="limitnumber(turn.title)"></td>
                <td v-html="limitnumber(turn.author)"></td>
                <td>
                               <%
                                                if (checkAuth("轮播排序", input)) {
                                            %>
                    <a class="upordown" @click="upordown($event,turn)">
                    <input type="hidden" class='tid' />
                    <input type="hidden" class='order_id'  />
                    上移
                    </a>
                    <a  class="upordown" @click="upordown($event,turn)" >
                    <input type="hidden" class='tid' />
                    <input type="hidden" class='order_id'/>
                    下移
                    </a>
                              <%
                                                }
                                            %>

                                <%
                                                if (checkAuth("移除轮播", input)) {
                                            %>
                     <a  class="delete_top"  @click="delete_news(turn)">移除</a></td>
                                        <%
                                                }
                                            %>
                </tr>
              </template>
                </table>
                </div>
          </div>
    </div>
    </div>
    <script src="../js/sweetalert-dev.js"></script>
<script>
    new Vue({
    el:"#turn_box",
    data:{
        turns:[]
    },
    ready:function(){
    var self = this;
    $.ajax({
        type: 'post',
        url: "turn.jsp",
        data: {
        act:"tops",
        },
        timeout: 3000,
        dataType: 'json',
        success: function(res) {
            if (res.errcode == 0) {
            self.turns= res.data;
            }
        },
        error: function(error) {

        }
    });
    },
    methods:{
    limitnumber:function(txt) {
        if(txt.length>8){
        txt = txt.substr(0,8) + '......' ;
        return txt;
        }
        else{
        return txt;
        }

    },
    upordown:function(event,turn){
        var tid=turn.tid;
        var order_id=turn.order_id;
        var act;
        if(event.currentTarget.text.trim()=="上移"){
            act='up'
        }else{
            act='down'
        }
        $.ajax({
            type: 'post',
            url: "turn.jsp",
            data: {
                act:'top_order',
                mod:act,
                tid:tid,
                order_id:order_id,
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                window.location.reload()
            },
            error:function (error) {
                alert("移动失败！")
            }
        });
    },
    delete_news:function(turn){
    swal({
        title: "您确定要移除吗？",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "是的，我要移除",
        cancelButtonText:"取消",
        confirmButtonColor: "#ec6c62"
    },
    function(){
    var news_id=turn.news_id;
        $.ajax({
            type: 'post',
            url: "content.jsp",
            data: {
            act:'unset_top',
            news_id:news_id,
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                if(data.errcode==0){
                self.location.reload();
            }else{
                 swal('删除失败')
            }
            },
            error:function (error) {
            swal('删除失败')
            }
        });
        return false;//阻止提交
        }
        );

    },
    }
    })
</script>
</body>
</html>
